package com.sz.sendmsg.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sz.sendmsg.entity.Log;
import com.sz.sendmsg.entity.Manager;
import com.sz.sendmsg.feign.LogFeign;
import org.apache.shiro.SecurityUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.UUID;

@Aspect
@Component
public class WebLogAspect {

    @Autowired
    LogFeign logFeign;
    @Before(value = "execution(* com.sz.sendmsg.controller.ShiroController.*(..))")
    public void before(JoinPoint joinPoint) throws Throwable {
        String name = joinPoint.getSignature().getName();
        Manager manager = (Manager) SecurityUtils.getSubject().getPrincipal();
        System.out.println(manager);
        if(manager != null){
            Log log = new Log();
            log.setLogId(UUID.randomUUID().toString());
            log.setOperator(manager.getLoginName());
            log.setOperationContent(name);
            logFeign.addLog(log);
        }

    }
}
